<?php
/**
 * jishupu-cms
 * @Author:技术铺
 * @Date: 2021/11/15
 */

use App\Http\Controllers\AdminLogController;
use App\Http\Controllers\AdsController;
use App\Http\Controllers\AdsSpaceController;
use App\Http\Controllers\AttachmentController;
use App\Http\Controllers\CaptchaController;
use App\Http\Controllers\CacheController;
use App\Http\Controllers\ConfigController;
use App\Http\Controllers\Example\ExampleTableController;
use App\Http\Controllers\Example\ExampleTreeTableController;
use App\Http\Controllers\DictionaryController;
use App\Http\Controllers\DictionaryItemsController;
use App\Http\Controllers\GuestbookController;
use App\Http\Controllers\InfoCategoryController;
use App\Http\Controllers\InfoModelController;
use App\Http\Controllers\InfoNewsController;
use App\Http\Controllers\InfoPageController;
use App\Http\Controllers\InfoPictureController;
use App\Http\Controllers\LinksController;
use App\Http\Controllers\LoginController;
use App\Http\Controllers\MenuController;
use App\Http\Controllers\NavigationController;
use App\Http\Controllers\PermissionController;
use App\Http\Controllers\RoleController;
use App\Http\Controllers\RouteController;
use App\Http\Controllers\SystemInfoController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\UserRoleController;
use App\Http\Controllers\ViewLogController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::prefix('v1')->name("admin.")->group(function () {

    // 非登录组
    Route::middleware(['adminLog:login'])->group(function () {
        // 登录
        Route::post('login', [LoginController::class, 'login'])->name("login");
        // 验证码
        Route::get('captcha/img', [CaptchaController::class, 'img'])->name("captcha.img");
    });

    // 登录访问组
    Route::middleware(['auth:sanctum','permission.check', 'adminLog:basic'])->group(function () {

        // 退出
        Route::get('logout', [LoginController::class, 'logout'])->name('logout');

        // 附件管理
//        Route::apiResource('attachment', 'AttachmentController');
        Route::get('attachment/config', [AttachmentController::class, 'config'])->name('attachment.config');
        Route::post('attachment/upload', [AttachmentController::class, 'upload'])->name('attachment.upload');
        Route::post('attachment/upload-image', [AttachmentController::class, 'uploadImage'])->name('attachment.uploadImage');
        Route::post('attachment/upload-media', [AttachmentController::class, 'uploadMedia'])->name('attachment.uploadMedia');
        Route::get('attachment/list/{id}', [AttachmentController::class, 'list'])->name('attachment.list');

        // 系统配置
        Route::get('config', [ConfigController::class, 'show'])->name('config.show');
        Route::patch('config', [ConfigController::class, 'update'])->name('config.update');
        Route::get('config/site-config', [ConfigController::class, 'siteConfig'])->name('config.siteConfig');


        // 管理员
        Route::patch('user/{user}/status', [UserController::class, 'updateStatus'])->name('user.updateStatus');
        Route::patch('user/{user}/clear-login-fail-times', [UserController::class, 'clearLoginFailTimes'])->name('user.clearLoginFailTimes');
        Route::get('user/profile', [UserController::class, 'profile'])->name('user.profile');
        Route::patch('user/{user}/profile', [UserController::class, 'updateProfile'])->name('user.updateProfile');
        Route::get('user/{role}/role-user-list', [UserController::class, 'roleUserList'])->name('user.roleUserList');
        Route::apiResource('user', 'UserController');

        //菜单
        Route::patch('menu/{menu}/status', [MenuController::class, 'updateStatus'])->name('menu.updateStatus');
        Route::put('menu/sort', [MenuController::class, 'updateSort'])->name('menu.updateSort');
        Route::get('menu/role-menu-config', [MenuController::class, 'roleMenuConfig'])->name('menu.roleMenuConfig');
        Route::get('menu/{id}/parent-tree-config', [MenuController::class, 'parentTreeConfig'])->name('menu.parentTreeConfig');
        Route::get('menu/user-menu-config', [MenuController::class, 'userMenuConfig'])->name('menu.userMenuConfig');
        Route::apiResource('menu', 'MenuController');

        // 数据字典
        Route::patch('dictionary/{dictionary}/status', [DictionaryController::class, 'updateStatus'])->name('dictionary.updateStatus');
        Route::get('dictionary/common-config', [DictionaryController::class, 'commonConfig'])->name('dictionary.commonConfig');
        Route::apiResource('dictionary', 'DictionaryController');

        // 数组字典选项
        Route::patch('dictionary/{dictionary}/dictionary-items/{dictionary_item}/status', [DictionaryItemsController::class, 'updateStatus'])->name('dictionaryItems.updateStatus');
        Route::put('dictionary/{dictionary}/dictionary-items/sort', [DictionaryItemsController::class, 'updateSort'])->name('dictionaryItems.updateSort');
        Route::apiResource('dictionary.dictionary-items', 'DictionaryItemsController')->names([
            'index' => 'dictionaryItems.index',
            'store' => 'dictionaryItems.store',
            'show' => 'dictionaryItems.show',
            'update' => 'dictionaryItems.update',
            'destroy' => 'dictionaryItems.destroy',
        ]);

        // 路由模块
        Route::get('route/permission-route-config', [RouteController::class, 'permissionRouteConfig'])->name('route.permissionRouteConfig');


        // 角色管理
        Route::patch('role/{role}/status', [RoleController::class, 'updateStatus'])->name('role.updateStatus');
        Route::put('role/sort', [RoleController::class, 'updateSort'])->name('role.updateSort');
        Route::get('role/user-role-config', [RoleController::class, 'userRoleConfig'])->name('role.userRoleConfig');
        Route::apiResource('role', 'RoleController');


        // 操作日志
        Route::get('admin-log/login', [AdminLogController::class, 'login'])->name('adminLog.login');
        Route::get('admin-log', [AdminLogController::class, 'index'])->name('adminLog.index');

        // 信息模型
        Route::get('info-model/info-category-model-config', [InfoModelController::class, 'infoCategoryModelConfig'])->name('infoModel.infoCategoryModelConfig');
        Route::apiResource('info-model', 'InfoModelController')->only(['index', 'store'])->names([
            'index' => 'infoModel.index',
            'store' => 'infoModel.store',
        ]);

        // 信息栏目分类
        Route::get('info-category/{id}/parent-tree-config', [InfoCategoryController::class, 'parentTreeConfig'])->name('infoCategory.parentTreeConfig');
        Route::get('info-category/{id}/category-tree-config', [InfoCategoryController::class, 'categoryTreeConfig'])->name('infoCategory.categoryTreeConfig');
        Route::put('info-category/sort', [InfoCategoryController::class, 'updateSort'])->name('infoCategory.updateSort');
        Route::patch('info-category/{info_category}/status', [InfoCategoryController::class, 'updateStatus'])->name('infoCategory.updateStatus');
        Route::apiResource('info-category', 'InfoCategoryController')->names([
            'index' => 'infoCategory.index',
            'store' => 'infoCategory.store',
            'show' => 'infoCategory.show',
            'update' => 'infoCategory.update',
            'destroy' => 'infoCategory.destroy',
        ]);

        // 单页模块
        Route::get('/info-category/{info_category}/info-page', [InfoPageController::class, 'show'])->name('infoPage.show');
        Route::put('/info-category/{info_category}/info-page', [InfoPageController::class, 'update'])->name('infoPage.update');

        // 信息模型-文章模块
        Route::patch('info-category/{info_category}/info-news/{info_news}/status', [InfoNewsController::class, 'updateStatus'])->name('infoNews.updateStatus');
        Route::patch('info-category/{info_category}/info-news/{info_news}/top', [InfoNewsController::class, 'updateTop'])->name('infoNews.updateTop');
        Route::put('info-category/{info_category}/info-news/sort', [InfoNewsController::class, 'updateSort'])->name('infoNews.updateSort');
        Route::apiResource('info-category.info-news', 'InfoNewsController')->names([
            'index' => 'infoNews.index',
            'store' => 'infoNews.store',
            'show' => 'infoNews.show',
            'update' => 'infoNews.update',
            'destroy' => 'infoNews.destroy',
        ]);

        // 信息模型-图集模块
        Route::patch('info-category/{info_category}/info-picture/{info_picture}/status', [InfoPictureController::class, 'updateStatus'])->name('infoPicture.updateStatus');
        Route::patch('info-category/{info_category}/info-picture/{info_picture}/top', [InfoPictureController::class, 'updateTop'])->name('infoPicture.updateTop');
        Route::put('info-category/{info_category}/info-picture/sort', [InfoPictureController::class, 'updateSort'])->name('infoPicture.updateSort');
        Route::apiResource('info-category.info-picture', 'InfoPictureController')->names([
            'index' => 'infoPicture.index',
            'store' => 'infoPicture.store',
            'show' => 'infoPicture.show',
            'update' => 'infoPicture.update',
            'destroy' => 'infoPicture.destroy',
        ]);


        // 友情链接
        Route::patch('links/{link}/status', [LinksController::class, 'updateStatus'])->name('links.updateStatus');
        Route::put('links/sort', [LinksController::class, 'updateSort'])->name('links.updateSort');
        Route::apiResource('links', 'LinksController');

        // 广告位
        Route::patch('ads-space/{ads_space}/status', [AdsSpaceController::class, 'updateStatus'])->name('adsSpace.updateStatus');
        Route::get('ads-space/{ads_space}/ads-space-config', [AdsSpaceController::class, 'adsSpaceConfig'])->name('adsSpace.adsSpaceConfig');
        Route::apiResource('ads-space', 'AdsSpaceController')->names([
            'index' => 'adsSpace.index',
            'store' => 'adsSpace.store',
            'show' => 'adsSpace.show',
            'update' => 'adsSpace.update',
            'destroy' => 'adsSpace.destroy',
        ]);

        // 广告
        Route::patch('ads-space/{ads_space}/ads/{ad}/status', [AdsController::class, 'updateStatus'])->name('ads.updateStatus');
        Route::put('ads-space/{ads_space}/ads/sort', [AdsController::class, 'updateSort'])->name('ads.updateSort');
        Route::apiResource('ads-space.ads', 'AdsController')->names([
            'index' => 'ads.index',
            'store' => 'ads.store',
            'show' => 'ads.show',
            'update' => 'ads.update',
            'destroy' => 'ads.destroy',
        ]);

        // 留言咨询
        Route::patch('guestbook/{guestbook}/status', [GuestbookController::class, 'updateStatus'])->name('guestbook.updateStatus');
        Route::delete('guestbook/{guestbook}', [GuestbookController::class, 'destroy'])->name('guestbook.destroy');
        Route::get('guestbook', [GuestbookController::class, 'index'])->name('guestbook.index');


        // 导航模块
        Route::get('navigation/{id}/parent-tree-config', [NavigationController::class, 'parentTreeConfig'])->name('navigation.parentTreeConfig');
        Route::put('navigation/sort', [NavigationController::class, 'updateSort'])->name('navigation.updateSort');
        Route::patch('navigation/{navigation}/status', [NavigationController::class, 'updateStatus'])->name('navigation.updateStatus');
        Route::apiResource('navigation', 'NavigationController')->names([
            'index' => 'navigation.index',
            'store' => 'navigation.store',
            'show' => 'navigation.show',
            'update' => 'navigation.update',
            'destroy' => 'navigation.destroy',
        ]);

        // 清除缓存
        Route::delete('cache/clear', [CacheController::class, 'clear'])->name('cache.clear');

        // 访问量统计
        Route::get('view-log/statistics', [ViewLogController::class, 'statistics'])->name('viewLog.statistics');

        // 系统信息
        Route::get('system-info', [SystemInfoController::class, 'show'])->name('systemInfo.show');

        // 演示模块组
        Route::group([
            'namespace' => 'Example',
            'prefix' => 'example'
        ], function () {
            // 树形表格
            Route::get('example-tree-table/{id}/parent-tree-config', [ExampleTreeTableController::class, 'parentTreeConfig'])->name('exampleTreeTable.parentTreeConfig');
            Route::get('example-tree-table/tree-config', [ExampleTreeTableController::class, 'treeConfig'])->name('exampleTreeTable.treeConfig');
            Route::put('example-tree-table/sort', [ExampleTreeTableController::class, 'updateSort'])->name('exampleTreeTable.updateSort');
            Route::patch('example-tree-table/{example_tree_table}/status', [ExampleTreeTableController::class, 'updateStatus'])->name('exampleTreeTable.updateStatus');
            Route::apiResource('example-tree-table', 'ExampleTreeTableController')->names([
                'index' => 'exampleTreeTable.index',
                'store' => 'exampleTreeTable.store',
                'show' => 'exampleTreeTable.show',
                'update' => 'exampleTreeTable.update',
                'destroy' => 'exampleTreeTable.destroy',
            ]);

            // 普通表格
            Route::patch('example-table/{example_table}/status', [ExampleTableController::class, 'updateStatus'])->name('exampleTable.updateStatus');
            Route::apiResource('example-table', 'ExampleTableController')->names([
                'index' => 'exampleTable.index',
                'store' => 'exampleTable.store',
                'show' => 'exampleTable.show',
                'update' => 'exampleTable.update',
                'destroy' => 'exampleTable.destroy',
            ]);
        });

        // 权限管理
        Route::patch('permission/{permission}/status', [PermissionController::class, 'updateStatus'])->name('permission.updateStatus');
        Route::put('permission/sort', [PermissionController::class, 'updateSort'])->name('permission.updateSort');
        Route::post('permission/patch-store', [PermissionController::class, 'patchStore'])->name('permission.patchStore');
        Route::get('permission/menu-permission-tree-config', [PermissionController::class, 'menuPermissionTreeConfig'])->name('permission.menuPermissionTreeConfig');
        Route::apiResource('permission', 'PermissionController');
    });
});





